package com.export.thread;

import com.export.bean.model.StateModel;
import com.export.config.FileHandle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.*;

/**
 * Created by MeowParse on 2017/5/10.
 * 将文件夹打包,删除文件夹
 */
@Component("PackThread")
@Scope("prototype")
public class PackThread extends Thread{

    private static final Logger logger = LoggerFactory.getLogger(ActionThread.class);

    private String fileName;
    private String sourceFilePath;
    private String zipFilePath;
    private StateModel stateModel;

    public PackThread(String fileName,String sourceFilePath,String zipFilePath,StateModel stateModel) {

        this.fileName = fileName;
        this.sourceFilePath = sourceFilePath;
        this.zipFilePath = zipFilePath;
        this.stateModel = stateModel;

    }

    @Override
    public void run() {
        logger.info("Start packing/开始打包");
        FileHandle.fileToZip(sourceFilePath,zipFilePath,fileName);

        logger.info(sourceFilePath);
        logger.info("Start deleting the package source file/开始删除打包源文件");

        File file = new File(sourceFilePath);
        FileHandle.deleteAllFilesOfDir(file);
        logger.info("Complete the package and delete!/完成打包和删除");

        Thread uploadThread = new UploadThread(fileName+".zip",zipFilePath+fileName+".zip",stateModel);
        uploadThread.start();
    }

}
